package com.zhang.family_doctor.utils;

import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtils {

    /**
     * 生成随机UUID
     *
     * @return uuid
     */
    public static int genUUID() {
        int id = UUID.randomUUID().toString().replaceAll("-", "").hashCode();
        return id < 0 ? -id : id;
    }

    public static Matcher getPhone(String phone){
        //校验手机号
        String regex = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
        Pattern compile = Pattern.compile(regex);
        Matcher matcherPhone = compile.matcher(phone);
        return matcherPhone;
    }

    public static Matcher getIdCard(String idCard){
        //校验身份证
        String id_18 = "^[1-9][0-9]{5}(18|19|20)[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}([0-9]|(X|x))";
        String id_15 = "^[1-9][0-9]{5}[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{2}[0-9]";
        String id_valid = "(" + id_18 + ")" + "|" + "(" + id_15 + ")";
        Pattern pattern = Pattern.compile(id_valid);
        Matcher matcher = pattern.matcher(idCard);
        return matcher;
    }

    public static Matcher getName(String name){
        //真实校验姓名
        String reg = "^(([\u4e00-\u9fa5]{2,8})|([a-zA-Z]{2,16}))$";
        Pattern compile = Pattern.compile(reg);
        Matcher matcherName = compile.matcher(name);
        return matcherName;
    }
}
